home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
OLE2BOOK.ZIP
/
CHAP02.ZIP
/
CHAP02
/
PATRON
/
PAGES.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-07
|
15KB
|
723 lines
/*
* PAGES.CPP
* Original Starter Chapter 2
*
* Implementation of the CPages class. See PAGEWIN.CPP for additional
* member functions.
*
* Copyright (c)1993 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#include "patron.h"
HWND g_hDlgPrint=NULL;
BOOL g_fCancelPrint=FALSE;
/*
* CPages:CPages
* CPages::~CPages
*
* Constructor Parameters:
* hInst HINSTANCE of the application we're in.
*/
CPages::CPages(HINSTANCE hInst)
: CWindow(hInst)
{
m_cPages=0;
m_iPageCur=0xFFFF; //Pages are 0 indexed, so this is one before that.
m_hWndPageList=NULL;
/*
* Initialize to 2.54cm*2.54cm which is a page with no space for anything,
* just margins. 2.54cm=.5 inches on each margin.
*/
m_cx=LOMETRIC_PER_INCH;
m_cy=LOMETRIC_PER_INCH;
m_xPos=0L;
m_yPos=0L;
m_dwIDNext=0;
m_hDevMode=NULL;
return;
}
CPages::~CPages(void)
{
//Insure memory is cleaned up in the list
New();
if (NULL!=m_hFont && !m_fSystemFont)
DeleteObject(m_hFont);
if (NULL!=m_hWndPageList)
DestroyWindow(m_hWndPageList);
return;
}
/*
* CPages::FInit
*
* Purpose:
* Instantiates a pages window within a given parent. The
* parent may be a main application window, could be an MDI child
* window. We really do not care.
*
* Parameters:
* hWndParent HWND of the parent of this window
* pRect LPRECT that this window should occupy
* dwStyle DWORD containing the window's style flags. Should
* contain WS_CHILD | WS_VISIBLE in typical circumstances.
* uID UINT ID to associate with this window
* pv LPVOID unused for now.
*
* Return Value:
* BOOL TRUE if the function succeeded, FALSE otherwise.
*/
BOOL CPages::FInit(HWND hWndParent, LPRECT pRect, DWORD dwStyle
, UINT uID, LPVOID pv)
{
int cy;
m_hWnd=CreateWindowEx(WS_EX_NOPARENTNOTIFY, SZCLASSPAGES
, SZCLASSPAGES, dwStyle, pRect->left, pRect->top
, pRect->right-pRect->left, pRect->bottom-pRect->top
, hWndParent, (HMENU)uID, m_hInst, (LPVOID)this);
if (NULL==m_hWnd)
return FALSE;
/*
* Create the hidden listbox we'll use to track pages. We give it
* the owner-draw style so we can just store pointers in it.
*/
m_hWndPageList=CreateWindow("listbox", "Page List", WS_POPUP | LBS_OWNERDRAWFIXED
, 0, 0, 100, 100, HWND_DESKTOP, NULL, m_hInst, NULL);
if (NULL==m_hWndPageList)
return FALSE;
//Create a 14 point Arial font, or use the system variable font.
cy=MulDiv(-14, LOMETRIC_PER_INCH, 72);
m_hFont=CreateFont(cy, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE
, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY
, VARIABLE_PITCH | FF_SWISS, "Arial");
if (NULL==m_hFont)
{
m_hFont=(HFONT)GetStockObject(ANSI_VAR_FONT);
m_fSystemFont=TRUE;
}
return TRUE;
}
/*
* CPages::New
*
* Purpose:
* Cleans out and reinitializes the data to defaults.
*
* Parameters:
* None
*
* Return Value:
* None
*/
void CPages::New(void)
{
LPPAGE pPage;
UINT i;
//First walk the page list and clean out the allocations.
for (i=0; i < m_cPages; i++)
{
if (FPageGet(i, &pPage, FALSE))
delete pPage;
}
if (NULL!=m_hWndPageList)
SendMessage(m_hWndPageList, LB_RESETCONTENT, 0, 0L);
if (NULL!=m_hDevMode)
GlobalFree(m_hDevMode);
return;
}
/*
* CPages::RectGet
*
* Purpose:
* Returns the rectangle of the Pages window in parent coordinates.
*
* Parameters:
* pRect LPRECT in which to return the rectangle.
*
* Return Value:
* None
*/
void CPages::RectGet(LPRECT pRect)
{
RECT rc;
POINT pt;
//Retrieve the size of our rectangle in parent coordinates.
GetWindowRect(m_hWnd, &rc);
pt.x=rc.left;
pt.y=rc.top;
ScreenToClient(GetParent(m_hWnd), &pt);
SetRect(pRect, pt.x, pt.y, pt.x+(rc.right-rc.left)
, pt.y+(rc.bottom-rc.top));
return;
}
/*
* CPages::RectSet
*
* Purpose:
* Sets a new rectangle for the Pages window which sizes to fit.
* Coordinates are given in parent terms.
*
* Parameters:
* pRect LPRECT containing the new rectangle.
* fNotify BOOL indicating if we're to notify anyone of the change.
*
* Return Value:
* None
*/
void CPages::RectSet(LPRECT pRect, BOOL fNotify)
{
UINT cx, cy;
if (NULL==pRect)
return;
cx=pRect->right-pRect->left;
cy=pRect->bottom-pRect->top;
SetWindowPos(m_hWnd, NULL, pRect->left, pRect->top
, (UINT)cx, (UINT)cy, SWP_NOZORDER);
UpdateScrollRanges();
return;
}
/*
* CPages::SizeGet
*
* Purpose:
* Retrieves the size of the pages window in parent coordinates.
*
* Parameters:
* pRect LPRECT in which to return the size. The right and
* bottom fields will contain the dimensions.
*
* Return Value:
* None
*/
void CPages::SizeGet(LPRECT pRect)
{
RectGet(pRect);
return;
}
/*
* CPages::SizeSet
*
* Purpose:
* Sets a new size in parent coordinates for the Pages window.
*
* Parameters:
* pRect LPRECT containing the new rectangle.
* fNotify BOOL indicating if we're to notify anyone of the change.
*
* Return Value:
* None
*/
void CPages::SizeSet(LPRECT pRect, BOOL fNotify)
{
UINT cx, cy;
if (NULL==pRect)
return;
cx=pRect->right-pRect->left;
cy=pRect->bottom-pRect->top;
SetWindowPos(m_hWnd, NULL, 0, 0, (UINT)cx, (UINT)cy
, SWP_NOMOVE | SWP_NOZORDER);
UpdateScrollRanges();
return;
}
/*
* CPages::PageInsert
*
* Purpose:
* Creates a new page immediately after the current page. If there
* are no pages then this creates page 1.
*
* Parameters:
* uReserved UINT unused
*
* Return Value:
* UINT Index of the new page, 0 on failure.
*/
UINT CPages::PageInsert(UINT uReserved)
{
//Create and open the new page.
if (!FPageAdd(m_iPageCur, m_dwIDNext, TRUE))
return 0;
m_dwIDNext++;
m_iPageCur++;
m_cPages++;
InvalidateRect(m_hWnd, NULL, FALSE);
UpdateWindow(m_hWnd);
return m_iPageCur;
}
/*
* CPages::PageDelete
*
* Removes the current page from the page list.
*
* Parameters:
* uReserved UINT unused
*
* Return Value:
* UINT Index to the now current page from the page list,
* -1 on error.
*/
UINT CPages::PageDelete(UINT uReserved)
{
LPPAGE pPage;
if (!FPageGet(m_iPageCur, &pPage, FALSE))
return -1;
//Delete the page in both the the listbox and in memory.
SendMessage(m_hWndPageList, LB_DELETESTRING, m_iPageCur, 0L);
delete pPage;
/*
* If this is the last page then the current is one less. If it's
* the only page the current is zero. Otherwise the current is the
* next page.
*/
if (m_iPageCur==m_cPages-1) //Covers last or only page.
m_iPageCur--;
m_cPages--;
if (0!=m_cPages)
InvalidateRect(m_hWnd, NULL, FALSE);
else
InvalidateRect(m_hWnd, NULL, TRUE);
UpdateWindow(m_hWnd);
return m_iPageCur;
}
/*
* CPages::CurPageGet
*
* Purpose:
* Retrieves the index of the current page we're viewing.
*
* Parameters:
* None
*
* Return Value:
* UINT